/*
 * Name: Minh-Tuan ta
 * Class: Home.java
 */

package actions;

/*
 * Name: Minh-Tuan ta
 * Class:Home.java
 */

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.*;

import data.ContentDB;
import data.ContentTypeDB;

import utils.Utils;
import java.util.*;

public class Home extends Action {

	@Override
	protected String doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		if (Utils.isLoggedIn(request)) //the user logged in
		{
			HttpSession session = request.getSession();
			User user = (User)session.getAttribute("User");
			ArrayList<Content> updates = ContentDB.getFriendsUpdates(user.getUserID());
			Map<String, Integer> contentTypeMap = ContentTypeDB.getContentTypeMap();
			request.setAttribute("updates", updates);
			request.setAttribute("contentTypeMap", contentTypeMap);
		}
		else
		{
		}
		
		
		return "/WEB-INF/views/content/Home.jsp";
	}

	@Override
	protected String doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void setURLMapping() {
		// TODO Auto-generated method stub
		this.urlMapping = "/Home";
	}

	@Override
	protected void setupPage(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		if (Utils.isLoggedIn(request))
		{
			request.setAttribute("pageTitle", "Home");
		}
		else
		{
			request.setAttribute("pageTitle", "UAFSBook Home");
		}
	}

}
